﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Action_Add : BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //判断用户权限
        //系统处理一场信息,多用户无权限,
        //则执行App_Code/BasePage.cs 内的方法:NoActionPower(object sender, EventArgs e);
        //可自行修改此方法
        UserPower.CheckAction((int)FreeHouse.Power.Actions.TAction.Add);
        if (!IsPostBack) BindData();
    }
    protected void save_Click(object sender, EventArgs e)
    {
        FreeHouse.Model.TAction action = new FreeHouse.Model.TAction();
        action.ActionClassID = int.Parse(ActionClassID.SelectedValue);
        action.MethodName = ActionName.Text.Trim();
        action.Description = Server.HtmlEncode(Description.Value);
        error.Items.Clear();
        error.Style.Add("color","#F00");
        if (action.ActionClassID == 0)
            error.Items.Add(new ListItem("填写action 所胡Action类"));
        if (action.MethodName == "")
            error.Items.Add(new ListItem("填写MethodName"));
        if (error.Items.Count == 0)
        {
            if (new FreeHouse.BLL.TAction().Exists(action.ActionClassID,action.MethodName))
            {
                error.Items.Add(new ListItem("此action 已存在."));
                return;
            }
            if (new FreeHouse.BLL.TAction().Add(action) > 0)
            {
                Response.Write("<script>alert('Action 添加成功.');location.href='add.aspx';</script>");
                Response.End();
            }
        }
    }

    protected void BindData()
    {
        ActionClassID.DataSource = new FreeHouse.BLL.TActionClass().GetList(100000,"","ClassName asc");
        ActionClassID.DataTextField = "ClassName";
        ActionClassID.DataValueField = "ActionClassID";
        ActionClassID.DataBind();
        ActionClassID.Items.Insert(0,new ListItem("请选择...","0"));
    }
}
